const path = require("path");
const knex = require("knex");
const jsyaml = require("js-yaml");
const fs = require("fs");
const dbConfigPath = path.join(__dirname, "db.config.yaml");
const dbConfig = jsyaml.load(fs.readFileSync(dbConfigPath, "utf8"));
if (!dbConfig) {
  console.error("db数据库文件不存在");
  process.exit(1);
}
console.log("Database configuration:", dbConfig);

const db = knex(dbConfig.db);
db.schema
  .createTableIfNotExists("typewritertexts", (table) => {
    table.increments("id").primary();
    table.timestamps(true, true);
    table.string("name");
  })
  .then(() => {
    console.log('Table "typewritertexts" created or already exists.');
  });
module.exports = { db, knex };
